package com.guigu.health.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.health.dao.MemberMapper;
import com.guigu.health.dao.MemberTwoMapper;
import com.guigu.health.pojo.Member;
import com.guigu.health.pojo.MemberExample;
import com.guigu.health.pojo.MemberTwo;
import com.guigu.health.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:MemberServiceImpl
 * @Description:
 * @Author:longtao
 * @Date:2021/3/31
 * @Version:1.0
 */
@Service("memberService")
public class MemberServiceImpl implements MemberService {

   private MemberMapper memberMapper;
   @Autowired
   @Qualifier("memberMapper")
    public void setMemberMapper(MemberMapper memberMapper) {
        this.memberMapper = memberMapper;
    }

    private MemberTwoMapper memberTwoMapper;
   @Autowired
   @Qualifier(value = "memberTwoMapper")
    public void setMemberTwoMapper(MemberTwoMapper memberTwoMapper) {
        this.memberTwoMapper = memberTwoMapper;
    }

    @Override
    public Member queryByAccount(String account) {
        return memberMapper.queryByAccount(account);
    }

    @Override
    public PageInfo<Member> queryAll(MemberExample example, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Member> list=memberMapper.selectByExample(example);
        PageInfo<Member> pageInfo=new PageInfo<Member>(list);
       return pageInfo;
    }

    @Override
    public boolean DeleteMemberById(Integer id) {
       boolean flag=false;
        int i = memberMapper.deleteByPrimaryKey(id);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean UpdateMemberById(Member member,MemberExample example) {
       boolean flag=false;
        int i = memberMapper.updateByExampleSelective(member, example);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    /**
     * 统计每天的预约数量
     * @param date
     * @return
     */
    @Override
    public List<Integer> getCount(List<String> date) {
        List<Integer> list=new ArrayList<Integer>();
        if (date!=null){
            for (String s : date) {
                int count=memberMapper.getCount(s);
                list.add(count);
            }
        }
       return list;
    }

    @Override
    public MemberTwo queryAll(String account) {
        MemberTwo query = memberTwoMapper.query(account);
        return query;
    }
}
